import 'package:flutter/widgets.dart';

class LearningPageTranslation {
  static final delegate = _LearningPageTranslationDelegate();

  static LearningPageTranslation of(BuildContext context) {
    return Localizations.of(context, LearningPageTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get title {
    return _resolve(const {
      'ru': 'Обучение',
      'en': 'Learning',
    });
  }

  String get learningStartButtonTitle {
    return _resolve(const {
      'ru': 'Начать обучение',
      'en': 'Start learning',
    });
  }

  String get premiumFeatureBlockTitle {
    return _resolve(const {
      'ru': 'Angry\u00a0Words\u00a0Pro',
      'en': 'Angry\u00a0Words\u00a0Pro',
    });
  }

  String get dailyUnlimitPremiumFeatureLabel {
    return _resolve(const {
      'ru': 'Без дневного ограничения',
      'en': 'No daily limit',
    });
  }

  String get exerciseShufflePremiumFeatureLabel {
    return _resolve(const {
      'ru': 'Перемешивание упражнений',
      'en': 'Shuffle of exercises',
    });
  }

  String get allLearningContentPremiumFeatureLabel {
    return _resolve(const {
      'ru': 'Любые слова и коллекции',
      'en': 'Any words and collections',
    });
  }

  String get imagePremiumFeatureLabel {
    return _resolve(const {
      'ru': 'Картинки к словам',
      'en': 'Images to the words',
    });
  }

  String get themeCustomizationPremiumFeatureLabel {
    return _resolve(const {
      'ru': 'Кастомизация темы',
      'en': 'Theme castomization',
    });
  }

  String get completelyLearnedLexicalItemCountTileTitle {
    return _resolve(const {
      'ru': 'Полностью выучено',
      'en': 'Completely learned',
    });
  }

  String get addedToLearningLexicalItemCountTileTitle {
    return _resolve(const {
      'ru': 'Добавлено на изучение',
      'en': 'Added to learning',
    });
  }

  String get repetitionCountTileTitle {
    return _resolve(const {
      'ru': 'Повторений',
      'en': 'Repetitions',
    });
  }

  String get learningDurationTileTitle {
    return _resolve(const {
      'ru': 'Время обучения',
      'en': 'Learning duration',
    });
  }

  String get _learningDurationHourAbbreviation {
    return _resolve(const {
      'ru': 'ч',
      'en': 'h',
    });
  }

  String get _learningDurationMinuteAbbreviation {
    return _resolve(const {
      'ru': 'мин',
      'en': 'min',
    });
  }

  String buildLearningDurationLabel({
    required int hours,
    required int minutes,
  }) {
    final hourAbbreviation = _learningDurationHourAbbreviation;
    final minuteAbbreviation = _learningDurationMinuteAbbreviation;

    if (hours >= 100 || hours > 0 && minutes == 0) {
      return '$hours $hourAbbreviation';
    }

    if (hours == 0) {
      return '$minutes $minuteAbbreviation';
    }

    return '$hours $hourAbbreviation $minutes $minuteAbbreviation';
  }

  String get todayStatisticsPeriodLabel {
    return _resolve(const {
      'ru': 'Сегодня',
      'en': 'Today',
    });
  }

  String get weekStatisticsPeriodLabel {
    return _resolve(const {
      'ru': 'Неделя',
      'en': 'Week',
    });
  }

  String get monthStatisticsPeriodLabel {
    return _resolve(const {
      'ru': 'Месяц',
      'en': 'Month',
    });
  }

  String get allTimeStatisticsPeriodLabel {
    return _resolve(const {
      'ru': 'Всего',
      'en': 'All time',
    });
  }

  String get vocabularySizeTileTitle {
    return _resolve(const {
      'ru': 'Словарный запас',
      'en': 'Vocabulary',
    });
  }

  String get beingLearnedLexicalItemCountTileTitle {
    return _resolve(const {
      'ru': 'Сейчас на изучении',
      'en': 'Being learned now',
    });
  }
}

class _LearningPageTranslationDelegate extends LocalizationsDelegate<LearningPageTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<LearningPageTranslation> old) => false;

  @override
  Future<LearningPageTranslation> load(Locale locale) async {
    final translation = LearningPageTranslation();
    await translation.load(locale);
    return translation;
  }
}
